commit
var target = UIATarget.localTarget();
var app = target.frontMostApp();

//Time delay running test script
var timeDelay = 0.5;


//Displaying the Element Hierarchy on screen

app.logElementTree();

UIALogger.logMessage("Displaying the Element Hierarchy on screen");
target.delay(1);

// Capture Screen
target.captureScreenWithName("HomeScreen");

//Stress test function Add new item
/*
//Add 10 items to list
UIALogger.logMessage("Add 10 items into list");
for (i = 1; i <= 10; i++) { 
    app.navigationBar().buttons()["Add"].tap();
 	UIALogger.logMessage("Tap the Add button");
	target.delay(timeDelay);
	app.mainWindow().textFields()[0].setValue("item " + i);
	target.delay(timeDelay);
	app.navigationBar().buttons()["Save"].tap();
 	UIALogger.logMessage("Tap the Save button");
	UIALogger.logMessage("Added item" + i);
 	UIALogger.logTrue();
	target.delay(timeDelay);
	app.navigationBar().buttons()["Recipes"].tap();
	target.delay(timeDelay);
}
*/


//test UI
//Testcase 1: Add new item to list (case: successful)
var cellsArray = app.mainWindow().tableViews()[0].cells();
var numberRowsBefore = cellsArray.length;
UIALogger.logMessage("Number of rows tableView before add 1 item: " + numberRowsBefore);
app.navigationBar().buttons()["Add"].tap();
UIALogger.logMessage("Tap the Add button");
target.captureScreenWithName("AddNewItemScreen");
target.delay(timeDelay);
app.mainWindow().textFields()[0].setValue("Automation test");
target.delay(timeDelay);
UIALogger.logMessage("Set value");
app.navigationBar().buttons()["Save"].tap();
UIALogger.logMessage("Tap the Save button");
target.delay(timeDelay);
target.captureScreenWithName("DescriptionScreen");
app.navigationBar().buttons()["Recipes"].tap();
UIALogger.logMessage("Tap the Recipes button");
target.delay(timeDelay);
var cellsArray = app.mainWindow().tableViews()[0].cells();
var numberRowsAfter = cellsArray.length;
UIALogger.logMessage("Number of rows tableView after add 1 item: " + numberRowsAfter);

//Number of row tableview increase 1 item after add
if(numberRowsBefore == (numberRowsAfter - 1))
{
	UIALogger.logPass("TestCase 1: -  Add new item is successful");
}
else
{
	UIALogger.logFail();
}



//Testcase 2: Add new item to list (case: fail for maximum 20 items)
var maxItem = 20;
app.navigationBar().buttons()["Add"].tap();
UIALogger.logMessage("Tap the Add button");
target.delay(timeDelay);
app.mainWindow().textFields()[0].setValue("Automation test");
target.delay(timeDelay);
UIALogger.logMessage("Set value");
app.navigationBar().buttons()["Save"].tap();
UIALogger.logMessage("Tap the Save button");
target.delay(timeDelay);
app.navigationBar().buttons()["Recipes"].tap();
UIALogger.logMessage("Tap the Recipes button");
target.delay(timeDelay);
var cellsArray = app.mainWindow().tableViews()[0].cells();
var numberRowsAfter = cellsArray.length;
UIALogger.logMessage("Number of rows tableView after add 1 item: " + numberRowsAfter);

//list limit 20 items
if(numberRowsAfter <= maxItem)
{
	UIALogger.logPass("TestCase 2: Add new item is successful");
}
else
{
	UIALogger.logFail("TestCase 2: Maximum 20 items");
}



